﻿Imports SIGI.Common.BE
Imports System.Data.SqlClient
Imports System.Configuration

Public Class DocumentTypeDAC

#Region "<< -Search- >>"
    Public Shared Function Search() As List(Of DocumentTypeBE)
        Dim wSqlConn As SqlConnection = Nothing
        Dim wSqlCmd As SqlCommand = Nothing
        Dim wReader As SqlDataReader = Nothing
        Dim wConnStr As String = String.Empty

        Dim wDocTypeList As List(Of DocumentTypeBE) = Nothing
        Dim wDocTypeBE As DocumentTypeBE = Nothing

        Try
            'Obtengo la cadena de conexión
            wConnStr = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            'Creo la conexión a la BD
            wSqlConn = New SqlConnection(wConnStr)
            'Creo el comando
            wSqlCmd = New SqlCommand()
            wSqlCmd.Connection = wSqlConn
            wSqlCmd.CommandType = CommandType.StoredProcedure
            wSqlCmd.CommandText = "Tipo_Documento_s"

            'Abro la conexión a la BD
            wSqlConn.Open()

            wDocTypeList = New List(Of DocumentTypeBE)
            wReader = wSqlCmd.ExecuteReader()
            While wReader.Read
                wDocTypeBE = New DocumentTypeBE

                wDocTypeBE.Id = Convert.ToInt32(wReader("Tipo_Doc"))
                wDocTypeBE.Description = Convert.ToString(wReader("Descripcion"))

                wDocTypeList.Add(wDocTypeBE)
            End While

            wSqlConn.Close()
        Catch ex As Exception
            Throw ex
        Finally
            wReader = Nothing
            wSqlCmd = Nothing
            wSqlConn = Nothing
        End Try

        Return wDocTypeList
    End Function
#End Region

End Class
